//
//  ListViewController.m
//  here
//
//  Created by 杜承玖 on 2/10/15.
//  Copyright (c) 2015 redianying. All rights reserved.
//

#import "ListViewController.h"
#import "ViewController.h"
#import "Function.h"

#define ksListToFlash @"listToShow"

@interface ListViewController()

@property (nonatomic, strong) NSArray * colorList;
@property (nonatomic, strong) UIColor * color;

@end


@implementation ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    [self setNeedsStatusBarAppearanceUpdate];
     */
    
    _colorList = [NSArray arrayWithObjects:
                  [Function colorWithHexString:@"FFFFFF"],
                  [Function colorWithHexString:@"F8DF44"],
                  [Function colorWithHexString:@"4DE69E"],
                  [Function colorWithHexString:@"25C1D8"],
                  [Function colorWithHexString:@"8d59c0"],
                  [Function colorWithHexString:@"d84791"],
                  [Function colorWithHexString:@"D73535"],
                  nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _colorList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [UIScreen mainScreen].bounds.size.height / 7.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                      reuseIdentifier:CellIdentifier];
    }
    UIColor *color = _colorList[indexPath.row];
    cell.backgroundColor = color;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    UIColor *color = _colorList[indexPath.row];
    [self performSegueWithIdentifier:ksListToFlash sender:color];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ( [segue.identifier isEqualToString:ksListToFlash] ) {
        ViewController * vc = segue.destinationViewController;
        vc.color = sender;
    }
}

@end
